# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[self.wydb = wydb
record = wydb.reference(config.wyplayer_dbus_bus_name, config.wyplayer_dbus_record_path_name)
self.rec_new = record.method('new', 's', 'o')
self.rec_del = record.method('del', 'o', '')
self.recorder_to_delete_list = []
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76aff6c>}
nname: 199
n 199(None)[timestep(config.wyplayer_dbus_record_path_name + ' new')
log.debug('new_dbuspath= ' + new_dbuspath)
reference = self.wydb.reference(config.wyplayer_dbus_bus_name, new_dbuspath)
return ExternalRecorder(dest_uri, reference, new_dbuspath)
]:
	i: 136(), 165(), 197(AE)
	o: 

nname: 197
n 197(None)[]:
	i: 155(f)
	o: 199(AE)

nname: 165
n 165(None)[#, e
log.debug(str(e))
return False
]:
	i: 155(t)
	o: 199()

nname: 155
n 155(<dummy_ex3> EXC_MATCH BaseException)[]:
	i: 0(except)
	o: 165(t), 197(f)

nname: 136
n 136(None)[new_dbuspath = self.rec_new(dest_uri)
]:
	i: 0(try)
	o: 199()

nname: 0
n 0(None)[log.info('ExternalRecorderFactory called: getNewExternalRecorder' + dest_uri)
dest_dir = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
log.debug('dest_dir timeshift ' + dest_dir)
os.makedirs(dest_dir)
dest_uri = dest_uri + '?cksize=' + str(config.timeshift_chunk_max_size) + '&recsize=' + str(config.max_size_for_timeshift) + '&silent_seek=1'
timestep('rec_new_init')
]:
	i: 
	o: 136(try), 155(except)

nname: 155
n 155(None)[except BaseException, e:
	log.debug(str(e))
	return False
timestep(config.wyplayer_dbus_record_path_name + ' new')
log.debug('new_dbuspath= ' + new_dbuspath)
reference = self.wydb.reference(config.wyplayer_dbus_bus_name, new_dbuspath)
return ExternalRecorder(dest_uri, reference, new_dbuspath)
]:
	i: 0()
	o: 

nname: 0
n 0(None)[log.info('ExternalRecorderFactory called: getNewExternalRecorder' + dest_uri)
dest_dir = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
log.debug('dest_dir timeshift ' + dest_dir)
os.makedirs(dest_dir)
dest_uri = dest_uri + '?cksize=' + str(config.timeshift_chunk_max_size) + '&recsize=' + str(config.max_size_for_timeshift) + '&silent_seek=1'
timestep('rec_new_init')
try:
	new_dbuspath = self.rec_new(dest_uri)
]:
	i: 
	o: 155()

nname: 0
n 0(None)[log.info('ExternalRecorderFactory called: getNewExternalRecorder' + dest_uri)
dest_dir = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
log.debug('dest_dir timeshift ' + dest_dir)
os.makedirs(dest_dir)
dest_uri = dest_uri + '?cksize=' + str(config.timeshift_chunk_max_size) + '&recsize=' + str(config.max_size_for_timeshift) + '&silent_seek=1'
timestep('rec_new_init')
try:
	new_dbuspath = self.rec_new(dest_uri)
except BaseException, e:
	log.debug(str(e))
	return False
timestep(config.wyplayer_dbus_record_path_name + ' new')
log.debug('new_dbuspath= ' + new_dbuspath)
reference = self.wydb.reference(config.wyplayer_dbus_bus_name, new_dbuspath)
return ExternalRecorder(dest_uri, reference, new_dbuspath)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76b1c8c>}
nname: 90
n 90(None)[]:
	i: 13(), 60(), 88(AE)
	o: 

nname: 88
n 88(None)[]:
	i: 50(f)
	o: 90(AE)

nname: 60
n 60(None)[#, e
log.debug(str(e))
]:
	i: 50(t)
	o: 90()

nname: 50
n 50(<dummy_ex3> EXC_MATCH BaseException)[]:
	i: 0(except)
	o: 60(t), 88(f)

nname: 13
n 13(None)[self.rec_del(ext_recorder.dbuspath)
timestep(config.wyplayer_dbus_record_path_name + ' delete')
]:
	i: 0(try)
	o: 90()

nname: 0
n 0(None)[timestep('deleteExternalRecorder init')
]:
	i: 
	o: 13(try), 50(except)

nname: 50
n 50(None)[except BaseException, e:
	log.debug(str(e))
]:
	i: 0()
	o: 

nname: 0
n 0(None)[timestep('deleteExternalRecorder init')
try:
	self.rec_del(ext_recorder.dbuspath)
	timestep(config.wyplayer_dbus_record_path_name + ' delete')
]:
	i: 
	o: 50()

nname: 0
n 0(None)[timestep('deleteExternalRecorder init')
try:
	self.rec_del(ext_recorder.dbuspath)
	timestep(config.wyplayer_dbus_record_path_name + ' delete')
except BaseException, e:
	log.debug(str(e))
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76b1b2c>}
nname: 192
n 192(None)[]:
	i: 146(JA), 188(), 191()
	o: 

nname: 191
n 191(None)[]:
	i: 28(f)
	o: 192()

nname: 188
n 188(None)[]:
	i: 120(JA), 187()
	o: 192()

nname: 187
n 187(None)[]:
	i: 62(f)
	o: 188()

nname: 146
n 146(None)[log.debug('remove timeshift folder: ' + folder_path)
removeFolder(folder_path)
timestep('delete_timeshift time')
]:
	i: 78(f)
	o: 192(JA)

nname: 120
n 120(None)[AsynchronousAction().appendAction(ActionRemoveFolder(folder_path))
]:
	i: 78(t)
	o: 188(JA)

nname: 78
n 78(config.asynchronous_chunk_removal)[folder_path = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
]:
	i: 62(t)
	o: 120(t), 146(f)

nname: 62
n 62(dest_uri.startswith(URL_PREFIX_REC_TIMESHIFT))[]:
	i: 28(t)
	o: 78(t), 187(f)

nname: 28
n 28(dest_uri)[dest_uri = recorder.dest_uri
ActionDeleteRecorderInstance(self, recorder).execute()
]:
	i: 6(), 27()
	o: 62(t), 191(f)

nname: 27
n 27(None)[]:
	i: 0(t)
	o: 28()

nname: 6
n 6(None)[log.debug('ask to delete a None recorder')
]:
	i: 0(f)
	o: 28()

nname: 0
n 0(recorder)[]:
	i: 
	o: 6(f), 27(t)

nname: 192
n 192(None)[]:
	i: 146(JA), 120(JA), 62(f), 0(f)
	o: 

nname: 146
n 146(None)[log.debug('remove timeshift folder: ' + folder_path)
removeFolder(folder_path)
timestep('delete_timeshift time')
]:
	i: 78(f)
	o: 192(JA)

nname: 120
n 120(None)[AsynchronousAction().appendAction(ActionRemoveFolder(folder_path))
]:
	i: 78(t)
	o: 192(JA)

nname: 78
n 78(config.asynchronous_chunk_removal)[folder_path = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
]:
	i: 62(t)
	o: 120(t), 146(f)

nname: 62
n 62(dest_uri.startswith(URL_PREFIX_REC_TIMESHIFT))[]:
	i: 0(t)
	o: 78(t), 192(f)

nname: 0
n 0(dest_uri)[if not recorder:
	log.debug('ask to delete a None recorder')
dest_uri = recorder.dest_uri
ActionDeleteRecorderInstance(self, recorder).execute()
]:
	i: 
	o: 62(t), 192(f)

nname: 0
n 0(None)[if not recorder:
	log.debug('ask to delete a None recorder')
dest_uri = recorder.dest_uri
ActionDeleteRecorderInstance(self, recorder).execute()
if dest_uri:
	if dest_uri.startswith(URL_PREFIX_REC_TIMESHIFT):
		folder_path = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
		if config.asynchronous_chunk_removal:
			AsynchronousAction().appendAction(ActionRemoveFolder(folder_path))
		else:
			log.debug('remove timeshift folder: ' + folder_path)
			removeFolder(folder_path)
			timestep('delete_timeshift time')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76b1cac>}
nname: 0
n 0(None)[self.deleteExternalRecorder(external_recorder)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76afcac>}
nname: 6
n 6(None)[def __init__(self, wydb):
	self.wydb = wydb
	record = wydb.reference(config.wyplayer_dbus_bus_name, config.wyplayer_dbus_record_path_name)
	self.rec_new = record.method('new', 's', 'o')
	self.rec_del = record.method('del', 'o', '')
	self.recorder_to_delete_list = []

def getNewExternalRecorder(self, dest_uri):
	log.info('ExternalRecorderFactory called: getNewExternalRecorder' + dest_uri)
	dest_dir = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
	log.debug('dest_dir timeshift ' + dest_dir)
	os.makedirs(dest_dir)
	dest_uri = dest_uri + '?cksize=' + str(config.timeshift_chunk_max_size) + '&recsize=' + str(config.max_size_for_timeshift) + '&silent_seek=1'
	timestep('rec_new_init')
	try:
		new_dbuspath = self.rec_new(dest_uri)
	except BaseException, e:
		log.debug(str(e))
		return False
	timestep(config.wyplayer_dbus_record_path_name + ' new')
	log.debug('new_dbuspath= ' + new_dbuspath)
	reference = self.wydb.reference(config.wyplayer_dbus_bus_name, new_dbuspath)
	return ExternalRecorder(dest_uri, reference, new_dbuspath)

def deleteExternalRecorder(self, ext_recorder):
	timestep('deleteExternalRecorder init')
	try:
		self.rec_del(ext_recorder.dbuspath)
		timestep(config.wyplayer_dbus_record_path_name + ' delete')
	except BaseException, e:
		log.debug(str(e))

def appendRecorderToDelete(self, recorder):
	if not recorder:
		log.debug('ask to delete a None recorder')
	dest_uri = recorder.dest_uri
	ActionDeleteRecorderInstance(self, recorder).execute()
	if dest_uri:
		if dest_uri.startswith(URL_PREFIX_REC_TIMESHIFT):
			folder_path = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
			if config.asynchronous_chunk_removal:
				AsynchronousAction().appendAction(ActionRemoveFolder(folder_path))
			else:
				log.debug('remove timeshift folder: ' + folder_path)
				removeFolder(folder_path)
				timestep('delete_timeshift time')

def deleteRecorder(self, external_recorder):
	self.deleteExternalRecorder(external_recorder)

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb76af86c>}
nname: 0
n 0(None)[]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76afb6c>}
nname: 0
n 0(None)[log.info('ExternalRecorderFactory called: getNewExternalRecorder' + dest_uri)
return DummyExternalRecorder(dest_uri, None, 'dummy')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76afc0c>}
nname: 0
n 0(None)[log.info('ExternalRecorderFactory called: deleteExternalRecorder')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76afeac>}
nname: 0
n 0(None)[log.info('ExternalRecorderFactory called: appendRecorderToDelete')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76afd6c>}
nname: 0
n 0(None)[log.info('ExternalRecorderFactory called: checkRecorderToDelete')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76afcec>}
nname: 6
n 6(None)[def __init__(self):
	pass

def getNewExternalRecorder(self, dest_uri):
	log.info('ExternalRecorderFactory called: getNewExternalRecorder' + dest_uri)
	return DummyExternalRecorder(dest_uri, None, 'dummy')

def deleteExternalRecorder(self, ext_recorder):
	log.info('ExternalRecorderFactory called: deleteExternalRecorder')

def appendRecorderToDelete(self, recorder):
	log.info('ExternalRecorderFactory called: appendRecorderToDelete')

def checkRecorderToDelete(self):
	log.info('ExternalRecorderFactory called: checkRecorderToDelete')

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb76af7cc>}
nname: 0
n 0(None)[from logger import log
import os
from externalrecorder import ExternalRecorder
from externalrecorder import DummyExternalRecorder
from config import *
from asynchronousaction import ActionRemoveFolder
from asynchronousaction import AsynchronousAction
from asynchronousaction import ActionDeleteRecorderInstance
from peewee.analyse import timestep
class ExternalRecorderFactory(object):
	def __init__(self, wydb):
		self.wydb = wydb
		record = wydb.reference(config.wyplayer_dbus_bus_name, config.wyplayer_dbus_record_path_name)
		self.rec_new = record.method('new', 's', 'o')
		self.rec_del = record.method('del', 'o', '')
		self.recorder_to_delete_list = []

	def getNewExternalRecorder(self, dest_uri):
		log.info('ExternalRecorderFactory called: getNewExternalRecorder' + dest_uri)
		dest_dir = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
		log.debug('dest_dir timeshift ' + dest_dir)
		os.makedirs(dest_dir)
		dest_uri = dest_uri + '?cksize=' + str(config.timeshift_chunk_max_size) + '&recsize=' + str(config.max_size_for_timeshift) + '&silent_seek=1'
		timestep('rec_new_init')
		try:
			new_dbuspath = self.rec_new(dest_uri)
		except BaseException, e:
			log.debug(str(e))
			return False
		timestep(config.wyplayer_dbus_record_path_name + ' new')
		log.debug('new_dbuspath= ' + new_dbuspath)
		reference = self.wydb.reference(config.wyplayer_dbus_bus_name, new_dbuspath)
		return ExternalRecorder(dest_uri, reference, new_dbuspath)

	def deleteExternalRecorder(self, ext_recorder):
		timestep('deleteExternalRecorder init')
		try:
			self.rec_del(ext_recorder.dbuspath)
			timestep(config.wyplayer_dbus_record_path_name + ' delete')
		except BaseException, e:
			log.debug(str(e))

	def appendRecorderToDelete(self, recorder):
		if not recorder:
			log.debug('ask to delete a None recorder')
		dest_uri = recorder.dest_uri
		ActionDeleteRecorderInstance(self, recorder).execute()
		if dest_uri:
			if dest_uri.startswith(URL_PREFIX_REC_TIMESHIFT):
				folder_path = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
				if config.asynchronous_chunk_removal:
					AsynchronousAction().appendAction(ActionRemoveFolder(folder_path))
				else:
					log.debug('remove timeshift folder: ' + folder_path)
					removeFolder(folder_path)
					timestep('delete_timeshift time')

	def deleteRecorder(self, external_recorder):
		self.deleteExternalRecorder(external_recorder)



class DummyExternalRecorderFactory(object):
	def __init__(self):
		pass

	def getNewExternalRecorder(self, dest_uri):
		log.info('ExternalRecorderFactory called: getNewExternalRecorder' + dest_uri)
		return DummyExternalRecorder(dest_uri, None, 'dummy')

	def deleteExternalRecorder(self, ext_recorder):
		log.info('ExternalRecorderFactory called: deleteExternalRecorder')

	def appendRecorderToDelete(self, recorder):
		log.info('ExternalRecorderFactory called: appendRecorderToDelete')

	def checkRecorderToDelete(self):
		log.info('ExternalRecorderFactory called: checkRecorderToDelete')



]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76a5bac>}
from logger import log
import os
from externalrecorder import ExternalRecorder
from externalrecorder import DummyExternalRecorder
from config import *
from asynchronousaction import ActionRemoveFolder
from asynchronousaction import AsynchronousAction
from asynchronousaction import ActionDeleteRecorderInstance
from peewee.analyse import timestep
class ExternalRecorderFactory(object):
	def __init__(self, wydb):
		self.wydb = wydb
		record = wydb.reference(config.wyplayer_dbus_bus_name, config.wyplayer_dbus_record_path_name)
		self.rec_new = record.method('new', 's', 'o')
		self.rec_del = record.method('del', 'o', '')
		self.recorder_to_delete_list = []

	def getNewExternalRecorder(self, dest_uri):
		log.info('ExternalRecorderFactory called: getNewExternalRecorder' + dest_uri)
		dest_dir = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
		log.debug('dest_dir timeshift ' + dest_dir)
		os.makedirs(dest_dir)
		dest_uri = dest_uri + '?cksize=' + str(config.timeshift_chunk_max_size) + '&recsize=' + str(config.max_size_for_timeshift) + '&silent_seek=1'
		timestep('rec_new_init')
		try:
			new_dbuspath = self.rec_new(dest_uri)
		except BaseException, e:
			log.debug(str(e))
			return False
		timestep(config.wyplayer_dbus_record_path_name + ' new')
		log.debug('new_dbuspath= ' + new_dbuspath)
		reference = self.wydb.reference(config.wyplayer_dbus_bus_name, new_dbuspath)
		return ExternalRecorder(dest_uri, reference, new_dbuspath)

	def deleteExternalRecorder(self, ext_recorder):
		timestep('deleteExternalRecorder init')
		try:
			self.rec_del(ext_recorder.dbuspath)
			timestep(config.wyplayer_dbus_record_path_name + ' delete')
		except BaseException, e:
			log.debug(str(e))

	def appendRecorderToDelete(self, recorder):
		if not recorder:
			log.debug('ask to delete a None recorder')
		dest_uri = recorder.dest_uri
		ActionDeleteRecorderInstance(self, recorder).execute()
		if dest_uri:
			if dest_uri.startswith(URL_PREFIX_REC_TIMESHIFT):
				folder_path = os.path.split(dest_uri[len(URL_PREFIX_REC_TIMESHIFT):])[0]
				if config.asynchronous_chunk_removal:
					AsynchronousAction().appendAction(ActionRemoveFolder(folder_path))
				else:
					log.debug('remove timeshift folder: ' + folder_path)
					removeFolder(folder_path)
					timestep('delete_timeshift time')

	def deleteRecorder(self, external_recorder):
		self.deleteExternalRecorder(external_recorder)



class DummyExternalRecorderFactory(object):
	def __init__(self):
		pass

	def getNewExternalRecorder(self, dest_uri):
		log.info('ExternalRecorderFactory called: getNewExternalRecorder' + dest_uri)
		return DummyExternalRecorder(dest_uri, None, 'dummy')

	def deleteExternalRecorder(self, ext_recorder):
		log.info('ExternalRecorderFactory called: deleteExternalRecorder')

	def appendRecorderToDelete(self, recorder):
		log.info('ExternalRecorderFactory called: appendRecorderToDelete')

	def checkRecorderToDelete(self):
		log.info('ExternalRecorderFactory called: checkRecorderToDelete')



